/*******************************************
 * Copyright 2007 Aphrodite Framework for javaME .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Email : owner@aphroditeme.dev.java.net
 * Contributors:
 *     Kent Elton - initial API and implementation
 *******************************************/

package com.aphrodite.ui.widgets;

import javax.microedition.lcdui.Graphics;

public class OutlineText extends Widget {
	private String text;

	public OutlineText(Theme theme, String text) {
		super(theme, 0, 0);
		this.text = text;
		updateModel();
	}

	public void cleanUp() {}

	public void render(Graphics g) {
		if (!isVisible)
			return;
		capture(g, width, height, false);
		g.setFont(theme.widgetFont);
		g.setColor(theme.fgColor);
		if (theme.bmFont != null) {
			theme.bmFont.drawString(g, text, 1, 1, Graphics.TOP | Graphics.LEFT);
			theme.bmFont.drawString(g, text, -1, -1, Graphics.TOP | Graphics.LEFT);
		} else {
			g.drawString(text, 1, 1, Graphics.TOP | Graphics.LEFT);
			g.drawString(text, -1, -1, Graphics.TOP | Graphics.LEFT);
		}
		g.setColor(theme.bgColor);
		if (theme.bmFont != null) {
			theme.bmFont.drawString(g, text, 0, 0, Graphics.TOP | Graphics.LEFT);
		} else
			g.drawString(text, 0, 0, Graphics.TOP | Graphics.LEFT);
		release(g, width, height, false);
	}

	// public void setFont(javax.microedition.lcdui.Font font) {
	// super.setFont(font);
	// updateModel();
	// reDraw();
	// stateChanged(this);
	// }

	protected void updateModel() {
		this.width = 2 + (theme.bmFont == null ? theme.widgetFont.stringWidth(text) : theme.bmFont.stringWidth(text));
		this.height = 2 + (theme.bmFont == null ? theme.widgetFont.getHeight() : theme.bmFont.getHeight());
		sizeChanged(width, height);
	}

}
